import dotenv from 'dotenv';

dotenv.config();

export interface OSSConfig {
  region: string;
  accessKeyId: string;
  accessKeySecret: string;
  bucket: string;
  endpoint?: string;
}

export const ossConfig: OSSConfig = {
  // OSS区域，例如：oss-cn-hangzhou, oss-cn-beijing 等
  region: process.env.OSS_REGION || '',
  // 从环境变量中获取访问凭证
  accessKeyId: process.env.OSS_ACCESS_KEY_ID || '',
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET || '',
  // 存储桶名称
  bucket: process.env.OSS_BUCKET_NAME || '',
  // 自定义域名（可选）
  endpoint: process.env.OSS_ENDPOINT
};

// 验证配置是否完整
export const validateOSSConfig = (): boolean => {
  const { region, accessKeyId, accessKeySecret, bucket } = ossConfig;
  
  if (!region || !accessKeyId || !accessKeySecret || !bucket) {
    console.error('OSS配置不完整，请检查环境变量：OSS_REGION、OSS_ACCESS_KEY_ID、OSS_ACCESS_KEY_SECRET、OSS_BUCKET_NAME');
    return false;
  }
  
  return true;
};